import java.util.Scanner;
import java.util.ArrayList;
import java.io.FileWriter;
import java.io.Writer;
import java.lang.StringBuilder;
import java.io.File;


public class CreateGetterAndSetter {
    private Writer writer;

    public CreateGetterAndSetter(File file) throws Exception {
        writer = new FileWriter(file);
    }

    public CreateGetterAndSetter(String stringFile) throws Exception {
        writer = new FileWriter(stringFile);
    }

    public CreateGetterAndSetter() {
        writer = null;
    }

    /**
     * 生成getter和setter方法
     * @return 生成的结果
     */
    public static String build(String[] prefix, String[] suffix) {
        StringBuilder result = new StringBuilder();

        for (int i = 0; i < prefix.length; i++) {
            String capitalStr = prefix[i].toUpperCase() + suffix[i];
            String str = prefix[i] + suffix[i];

            if (i != 0) {
                result.append("\n\n");
            }
            result.append("set set")
                .append(capitalStr)
                .append("(")
                .append(str)
                .append(") {\n")
                .append("    this.")
                .append(str)
                .append(" = ")
                .append(str)
                .append(";\n}");

            result.append("\n\nget get")
                .append(capitalStr)
                .append("() {\n")
                .append("    return this.")
                .append(str)
                .append(";\n}");
        }

        return result.toString();
    }

    public boolean outPutResult(String result) throws Exception {
        System.out.println("输出");
        // 检测输出环境
        if (this.writer == null) {
            System.out.println(result);
        } else {
            this.writer.write(result);
        }

        return true;
    }

    public static void main(String[] args) throws Exception{
        Scanner input = new Scanner(System.in);
        System.out.println("请输入要创建的属性, 最后一行换行并输入end来结束输入");

        // 保存输入的列表
        ArrayList<String> list = new ArrayList<>();

        while (!input.hasNext("end")) {
            list.add(input.nextLine());
        }
        // 保存属性的数组
        String[] capitalArrtibute = new String[list.size()];
        String[] arrtibuteArray = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            String tempStr = list.get(i).split("=")[0];
            capitalArrtibute[i] = "" + tempStr.charAt(0);
            arrtibuteArray[i] = tempStr.substring(1, tempStr.length() - 1);
        }

        // 控制台输出示例
        CreateGetterAndSetter test = new CreateGetterAndSetter();
        test.outPutResult(build(capitalArrtibute, arrtibuteArray));
    }
}